cd "C:\Users\jscho\Documents\Migration Research-- David Leblang & Justin Schon\Time Varying Effects of Border Walls\CPS submission\R&R\Replication"

use "Replication_CPS_Schon & Leblang.dta",clear

foreach var of varlist ref* {
	genl ln`var'=log(`var'+1)
	}
	
egen pull=group(iso_d year)

genl lngdppcconstant_o=log(gdppcconstant_o)
genl lndist=log(dist)

duplicates tag dyad year, gen(dupid)
drop if dupid>0

xtset dyad year

*sum of refugees in transit countries
genl lnrefugees_transit=log(origin_transit+1)
replace transit_destination=0 if transit_destination==.
genl lntransit_destination=log(transit_destination+1)

genl lnorigin_destination=log(origin_destination+1)
gen llnorigin_destination=l.lnorigin_destination

replace ln_boundary_length=0 if ln_boundary_length<0

gen lAvdan_barrier=l.Avdan_barrier
gen lPoast_barrier=l.Poast_barrier
gen lHassner_barrier=l.Hassner_barrier

gen lcivwar_intensity_o=l.civwar_intensity_o
gen lv2x_polyarchy_o=l.v2x_polyarchy_o
gen lgenocide_o=genocide_o
gen llngdppcconstant_o=lngdppcconstant_o
gen lpts_a_o=pts_a_o

pca mountain border_crossings ln_boundary_length

predict pc1 pc2 pc3, score

replace appliedduringyear=0 if appliedduringyear==.

gen log_asy= log(appliedduringyear+1)

******
*Figure 1: Refugee Population by Year, 1990-2016
*Graph made in R

******
*Figure 2: Border Barriers by Year
*1990-2013 for Avdan & Gelpi
*1990-2014 for Poast & Carter and Hassner & Wittenberg

/* Need to bracket this out to make code run
keep if border==1
collapse (sum) Avdan_barrier Poast_barrier Hassner_barrier, by(year)
twoway (tsline Poast_barrier Hassner_barrier if year>=1990 & year<=2014) ///
(tsline Avdan_barrier if year>=1990 & year<=2013)
*/

******
*Figure 3: Border Barriers Maps
** These were made in R. See R script for this.

******
*Figures 4-6 were made in ArcMap

/*
Table I: Descriptive Statistics table

drop if year<1989

balancetable Hassner_barrier origin_destination ///
civwar_intensity_o v2x_polyarchy_o genocide_o pts_a_o lngdppcconstant_o ///
lndist comlang_off colony using table1.xlsx
*/

******
*Figure 7: Poisson Results
*All dyads

capture drop count
capture drop Hp Ap
gen count=_n+1989 in 1/27
gen Hp=.
gen Ap=.
gen Pp=.
gen Hz=.
gen Az=.
gen Pz=.
foreach num of numlist 1990(1)2014 {
	 capture poisson lnorigin_destination  lHassner_barrier llnorigin_destination lcivwar_intensity_o lv2x_polyarchy_o lgenocide_o lpts_a_o llngdppcconstant_o lndist comlang_off colony  if year==`num' , cl(dyad) difficult nolog iterate(10000)
	 capture lincom lHassner_barrier
	 capture replace Hp=r(p) if count==`num'
	 capture replace Hz=r(z) if count==`num'
	 capture poisson lnorigin_destination  lAvdan_barrier llnorigin_destination lcivwar_intensity_o lv2x_polyarchy_o lgenocide_o lpts_a_o llngdppcconstant_o lndist comlang_off colony  if year==`num' & year!=2014, cl(dyad) difficult nolog iterate(10000)
	 capture lincom lAvdan_barrier
	 capture replace Ap=r(p) if count==`num'
	 capture replace Az=r(z) if count==`num'
	 capture poisson lnorigin_destination  lPoast_barrier llnorigin_destination lcivwar_intensity_o lv2x_polyarchy_o lgenocide_o lpts_a_o llngdppcconstant_o lndist comlang_off colony  if year==`num' , cl(dyad) difficult nolog iterate(10000)
	 capture lincom lPoast_barrier
	 capture replace Pp=r(p) if count==`num'
	 capture replace Pz=r(z) if count==`num'
}

label var Hz "Hassner & Wittenberg"
label var Az "Avdan & Gelpi"
label var Pz "Poast & Carter"


set scheme cleanplots

twoway (scatter Hz count, symbol(t)) (scatter Az count, symbol(o) yline(-2)) (scatter Pz count, symbol(s) yline(2)), saving(IO_all,replace)

drop Hp Hz Ap Az Pp Pz

******
*Figure 8: Poisson Results
*Contiguous dyads

preserve
keep if border==1
capture drop count
capture drop Hp Ap
gen count=_n+1989 in 1/27
gen Hp=.
gen Ap=.
gen Pp=.
gen Hz=.
gen Az=.
gen Pz=.
foreach num of numlist 1990(1)2014 {
	 capture poisson lnorigin_destination  lHassner_barrier llnorigin_destination lcivwar_intensity_o lv2x_polyarchy_o lgenocide_o lpts_a_o llngdppcconstant_o lndist comlang_off colony  if year==`num' , cl(dyad) difficult nolog iterate(10000)
	 capture lincom lHassner_barrier
	 capture replace Hp=r(p) if count==`num'
	 capture replace Hz=r(z) if count==`num'
	 capture poisson lnorigin_destination  lAvdan_barrier llnorigin_destination lcivwar_intensity_o lv2x_polyarchy_o lgenocide_o lpts_a_o llngdppcconstant_o lndist comlang_off colony  if year==`num' & year!=2014, cl(dyad) difficult nolog iterate(10000)
	 capture lincom lAvdan_barrier
	 capture replace Ap=r(p) if count==`num'
	 capture replace Az=r(z) if count==`num'
	 capture poisson lnorigin_destination  lPoast_barrier llnorigin_destination lcivwar_intensity_o lv2x_polyarchy_o lgenocide_o lpts_a_o llngdppcconstant_o lndist comlang_off colony  if year==`num' , cl(dyad) difficult nolog iterate(10000)
	 capture lincom lPoast_barrier
	 capture replace Pp=r(p) if count==`num'
	 capture replace Pz=r(z) if count==`num'
}

label var Hz "Hassner & Wittenberg"
label var Az "Avdan & Gelpi"
label var Pz "Poast & Carter"


set scheme cleanplots

twoway (scatter Hz count, symbol(t)) (scatter Az count, symbol(o) yline(-2)) (scatter Pz count, symbol(s) yline(2)), saving(IO_all,replace)

drop Hp Hz Ap Az Pp Pz

restore

*************
*Figure 9: IV Poisson
*** All dyads
/*
Drop lndist from ivpoisson gmm models so they converge
Drop PTS from Avdan since that has lots of missings and does not converge
*/

/*
Install with below code if cleanplots not already installed

net install cleanplots, from("https://tdmize.github.io/data/cleanplots")
*/

set scheme cleanplots

capture drop count
capture drop Hp Ap
gen count=_n+1989 in 1/27
gen Hp=.
gen Ap=.
gen Pp=.
gen Hz=.
gen Az=.
gen Pz=.
foreach num of numlist 1990(1)2014 {
	 capture ivpoisson gmm lnorigin_destination  (l.Hassner_barrier= mountain border_crossings ln_boundary_length) l.(civwar_intensity_o v2x_polyarchy_o genocide_o pts_a_o lngdppcconstant_o) comlang_off colony  if year==`num', vce(cl dyad)
	 capture lincom l.Hassner_barrier
	 capture replace Hp=r(p) if count==`num'
	 capture replace Hz=r(z) if count==`num' 
	 capture ivpoisson gmm lnorigin_destination  (l.Avdan_barrier= mountain border_crossings ln_boundary_length) l.(civwar_intensity_o v2x_polyarchy_o genocide_o lngdppcconstant_o) comlang_off colony  if year==`num' & year!=2014, vce(cl dyad)
	 capture lincom l.Avdan_barrier
	 capture replace Ap=r(p) if count==`num'
	 capture replace Az=r(z) if count==`num'
	 capture ivpoisson gmm lnorigin_destination  (l.Poast_barrier= mountain border_crossings ln_boundary_length) l.(civwar_intensity_o v2x_polyarchy_o genocide_o pts_a_o lngdppcconstant_o) comlang_off colony  if year==`num', vce(cl dyad)
	 capture lincom l.Poast_barrier
	 capture replace Pp=r(p) if count==`num'
	 capture replace Pz=r(z) if count==`num'
}

label var Hz "Hassner & Wittenberg"
label var Az "Avdan & Gelpi"
label var Pz "Poast & Carter"


twoway (scatter Hz count, symbol(t)) (scatter Az count, symbol(o) yline(-2)) (scatter Pz count, symbol(s) yline(2)), saving(ivpoisson_models,replace)

drop Hp Hz Ap Az Pp Pz count




/*
Make sure these two steps have been done
qui do "ivmediate.ado"
ssc install ranktest
*/

ivmediate lnorigin_destination lcivwar_intensity_o lv2x_polyarchy_o lgenocide_o lpts_a_o llngdppcconstant_o comlang_off colony lndist if year>=2000 & year<=2013, mediator(log_asy) treatment(lAvdan_barrier) instrument(pc1) full
ivmediate lnorigin_destination lcivwar_intensity_o lv2x_polyarchy_o lgenocide_o lpts_a_o llngdppcconstant_o comlang_off colony lndist if year>=2000 & year<=2013, mediator(log_asy) treatment(lAvdan_barrier) instrument(pc2) full
ivmediate lnorigin_destination lcivwar_intensity_o lv2x_polyarchy_o lgenocide_o lpts_a_o llngdppcconstant_o comlang_off colony lndist if year>=2000 & year<=2013, mediator(log_asy) treatment(lAvdan_barrier) instrument(pc3) full

ivmediate lnorigin_destination lcivwar_intensity_o lv2x_polyarchy_o lgenocide_o lpts_a_o llngdppcconstant_o comlang_off colony lndist if year>=2000 & year<=2013, mediator(log_asy) treatment(lPoast_barrier) instrument(pc1) full
ivmediate lnorigin_destination lcivwar_intensity_o lv2x_polyarchy_o lgenocide_o lpts_a_o llngdppcconstant_o comlang_off colony lndist if year>=2000 & year<=2013, mediator(log_asy) treatment(lPoast_barrier) instrument(pc2) full
ivmediate lnorigin_destination lcivwar_intensity_o lv2x_polyarchy_o lgenocide_o lpts_a_o llngdppcconstant_o comlang_off colony lndist if year>=2000 & year<=2013, mediator(log_asy) treatment(lPoast_barrier) instrument(pc3) full

ivmediate lnorigin_destination lcivwar_intensity_o lv2x_polyarchy_o lgenocide_o lpts_a_o llngdppcconstant_o comlang_off colony lndist if year>=2000 & year<=2013, mediator(log_asy) treatment(lHassner_barrier) instrument(pc1) full
ivmediate lnorigin_destination lcivwar_intensity_o lv2x_polyarchy_o lgenocide_o lpts_a_o llngdppcconstant_o comlang_off colony lndist if year>=2000 & year<=2013, mediator(log_asy) treatment(lHassner_barrier) instrument(pc2) full
ivmediate lnorigin_destination lcivwar_intensity_o lv2x_polyarchy_o lgenocide_o lpts_a_o llngdppcconstant_o comlang_off colony lndist if year>=2000 & year<=2013, mediator(log_asy) treatment(lHassner_barrier) instrument(pc3) full

********************************************************************************
*** Appendix
********************************************************************************

*******************************************************
*Table A1
*******************************************************
poisson lnorigin_destination  c.mountain c.border_crossings ///
c.ln_boundary_length l.(lnorigin_destination ///
civwar_intensity_o v2x_polyarchy_o genocide_o pts_a_o ///
lngdppcconstant_o) lndist comlang_off colony if year>=1990

*******************************************************
*Table A2
*******************************************************
logit Hassner_barrier  c.mountain c.border_crossings ///
c.ln_boundary_length l.(civwar_intensity_o ///
v2x_polyarchy_o genocide_o pts_a_o ///
lngdppcconstant_o) lndist comlang_off colony if year>=1990
outreg2 using firststage, word se label dec(3) title("Table A2: Logistic regression for border geography on barrier existence")
logit Poast_barrier  c.mountain c.border_crossings ///
c.ln_boundary_length l.(civwar_intensity_o ///
v2x_polyarchy_o genocide_o pts_a_o ///
lngdppcconstant_o) lndist comlang_off colony if year>=1990
outreg2 using firststage, word se label dec(3) append
logit Avdan_barrier  c.mountain c.border_crossings ///
c.ln_boundary_length l.(civwar_intensity_o ///
v2x_polyarchy_o genocide_o pts_a_o ///
lngdppcconstant_o) lndist comlang_off colony if year>=1990
outreg2 using firststage, word se label dec(3) append

********************************************************************
*Appendix
*Negative binomial
********************************************************************
capture drop count
capture drop Hp Ap
gen count=_n+1989 in 1/27
gen Hp=.
gen Ap=.
gen Pp=.
gen Hz=.
gen Az=.
gen Pz=.
foreach num of numlist 1990(1)2014 {
	 capture nbreg lnorigin_destination  lHassner_barrier llnorigin_destination lcivwar_intensity_o lv2x_polyarchy_o lgenocide_o lpts_a_o llngdppcconstant_o lndist comlang_off colony  if year==`num' , cl(dyad) difficult nolog iterate(10000)
	 capture lincom lHassner_barrier
	 capture replace Hp=r(p) if count==`num'
	 capture replace Hz=r(z) if count==`num'
	 capture nbreg lnorigin_destination  lAvdan_barrier llnorigin_destination lcivwar_intensity_o lv2x_polyarchy_o lgenocide_o lpts_a_o llngdppcconstant_o lndist comlang_off colony  if year==`num' , cl(dyad) difficult nolog iterate(10000)
	 capture lincom lAvdan_barrier
	 capture replace Ap=r(p) if count==`num'
	 capture replace Az=r(z) if count==`num'
	 capture nbreg lnorigin_destination  lPoast_barrier llnorigin_destination lcivwar_intensity_o lv2x_polyarchy_o lgenocide_o lpts_a_o llngdppcconstant_o lndist comlang_off colony  if year==`num' , cl(dyad) difficult nolog iterate(10000)
	 capture lincom lPoast_barrier
	 capture replace Pp=r(p) if count==`num'
	 capture replace Pz=r(z) if count==`num'
}

label var Hz "Hassner & Wittenberg"
label var Az "Avdan & Gelpi"
label var Pz "Poast & Carter"


twoway (scatter Hz count, symbol(t)) (scatter Az count, symbol(o) yline(-2)) (scatter Pz count, symbol(s) yline(2)), saving(APSA_all_dyads,replace)

drop Hp Hz Ap Az Pp Pz


********************************************************************
*Appendix
*Contiguous countries only
*Negative binomial
********************************************************************
preserve
keep if border==1
capture drop count
capture drop Hp Ap
gen count=_n+1989 in 1/27
gen Hp=.
gen Ap=.
gen Pp=.
gen Hz=.
gen Az=.
gen Pz=.
foreach num of numlist 1990(1)2014 {
	 capture nbreg lnorigin_destination  lHassner_barrier llnorigin_destination lcivwar_intensity_o lv2x_polyarchy_o lgenocide_o lpts_a_o llngdppcconstant_o lndist comlang_off colony  if year==`num' , cl(dyad) difficult nolog iterate(10000)
	 capture lincom lHassner_barrier
	 capture replace Hp=r(p) if count==`num'
	 capture replace Hz=r(z) if count==`num'
	 capture nbreg lnorigin_destination  lAvdan_barrier llnorigin_destination lcivwar_intensity_o lv2x_polyarchy_o lgenocide_o lpts_a_o llngdppcconstant_o lndist comlang_off colony  if year==`num' , cl(dyad) difficult nolog iterate(10000)
	 capture lincom lAvdan_barrier
	 capture replace Ap=r(p) if count==`num'
	 capture replace Az=r(z) if count==`num'
	 capture nbreg lnorigin_destination  lPoast_barrier llnorigin_destination lcivwar_intensity_o lv2x_polyarchy_o lgenocide_o lpts_a_o llngdppcconstant_o lndist comlang_off colony  if year==`num' , cl(dyad) difficult nolog iterate(10000)
	 capture lincom lPoast_barrier
	 capture replace Pp=r(p) if count==`num'
	 capture replace Pz=r(z) if count==`num'
}

label var Hz "Hassner & Wittenberg"
label var Az "Avdan & Gelpi"
label var Pz "Poast & Carter"


twoway (scatter Hz count, symbol(t)) (scatter Az count, symbol(o) yline(-2)) (scatter Pz count, symbol(s) yline(2)), saving(APSA_all_dyads,replace)

drop Hp Hz Ap Az Pp Pz
restore


**********************************************************************
*** Appendix OLS figure
**********************************************************************
capture drop count
capture drop Hp Ap
gen count=_n+1989 in 1/27
gen Hp=.
gen Ap=.
gen Pp=.
gen Ht=.
gen At=.
gen Pt=.
foreach num of numlist 1990(1)2014 {
	 capture reg lnorigin_destination  lHassner_barrier llnorigin_destination lcivwar_intensity_o lv2x_polyarchy_o lgenocide_o lpts_a_o llngdppcconstant_o lndist comlang_off colony  if year==`num', vce(cl dyad)
	 capture lincom lHassner_barrier
	 capture replace Hp=r(p) if count==`num'
	 capture replace Ht=r(t) if count==`num'
	 capture reg lnorigin_destination  lAvdan_barrier llnorigin_destination lcivwar_intensity_o lv2x_polyarchy_o lgenocide_o lpts_a_o llngdppcconstant_o lndist comlang_off colony  if year==`num', vce(cl dyad)
	 capture lincom lAvdan_barrier
	 capture replace Ap=r(p) if count==`num'
	 capture replace At=r(t) if count==`num'
	 capture reg lnorigin_destination  lPoast_barrier llnorigin_destination lcivwar_intensity_o lv2x_polyarchy_o lgenocide_o lpts_a_o llngdppcconstant_o lndist comlang_off colony  if year==`num', vce(cl dyad)
	 capture lincom lPoast_barrier
	 capture replace Pp=r(p) if count==`num'
	 capture replace Pt=r(t) if count==`num'
}

label var Ht "Hassner & Wittenberg"
label var At "Avdan & Gelpi"
label var Pt "Poast & Carter"


twoway (scatter Ht count, symbol(t)) (scatter At count, symbol(o) yline(-2)) (scatter Pt count, symbol(s) yline(2)), saving(reg_models,replace)

drop Hp Ht Ap At Pp Pt count


**********************************************************************
*** Appendix OLS-IV figure
**********************************************************************
capture drop count
capture drop Hp Ap
gen count=_n+1989 in 1/27
gen Hp=.
gen Ap=.
gen Pp=.
gen Hz=.
gen Az=.
gen Pz=.
foreach num of numlist 1990(1)2014 {
	 capture ivregress 2sls lnorigin_destination  (l.Hassner_barrier=ln_boundary_length) l.lnorigin_destination l.(civwar_intensity_o v2x_polyarchy_o genocide_o pts_a_o lngdppcconstant_o) lndist comlang_off colony  if year==`num', vce(cl dyad)
	 capture lincom l.Hassner_barrier
	 capture replace Hp=r(p) if count==`num'
	 capture replace Hz=r(z) if count==`num'
	 capture ivregress 2sls lnorigin_destination  (l.Avdan_barrier=ln_boundary_length) l.lnorigin_destination l.(civwar_intensity_o v2x_polyarchy_o genocide_o pts_a_o lngdppcconstant_o) lndist comlang_off colony  if year==`num', vce(cl dyad)
	 capture lincom l.Avdan_barrier
	 capture replace Ap=r(p) if count==`num'
	 capture replace Az=r(z) if count==`num'
	 capture ivregress 2sls lnorigin_destination  (l.Poast_barrier=ln_boundary_length) l.lnorigin_destination l.(civwar_intensity_o v2x_polyarchy_o genocide_o pts_a_o lngdppcconstant_o) lndist comlang_off colony  if year==`num', vce(cl dyad)
	 capture lincom l.Poast_barrier
	 capture replace Pp=r(p) if count==`num'
	 capture replace Pz=r(z) if count==`num'
}

label var Hz "Hassner & Wittenberg"
label var Az "Avdan & Gelpi"
label var Pz "Poast & Carter"


twoway (scatter Hz count, symbol(t)) (scatter Az count, symbol(o) yline(-2)) (scatter Pz count, symbol(s) yline(2)), saving(iv_models_log,replace)

drop Hp Hz Ap Az Pp Pz count




**********************************************************************
*** Appendix Tobit figure
**********************************************************************
capture drop count
capture drop Hp Ap
gen count=_n+1989 in 1/27
gen Hp=.
gen Ap=.
gen Pp=.
gen Ht=.
gen At=.
gen Pt=.
foreach num of numlist 1990(1)2014 {
	 capture tobit lnorigin_destination  l.Hassner_barrier l.lnorigin_destination l.(civwar_intensity_o v2x_polyarchy_o genocide_o pts_a_o lngdppcconstant_o) lndist comlang_off colony  if year==`num', ll(0) ul(14) vce(cl dyad)
	 capture lincom l.Hassner_barrier
	 capture replace Hp=r(p) if count==`num'
	 capture replace Ht=r(t) if count==`num'
	 capture tobit lnorigin_destination  l.Avdan_barrier l.lnorigin_destination l.(civwar_intensity_o v2x_polyarchy_o genocide_o pts_a_o lngdppcconstant_o) lndist comlang_off colony  if year==`num', ll(0) ul(14) vce(cl dyad)
	 capture lincom l.Avdan_barrier
	 capture replace Ap=r(p) if count==`num'
	 capture replace At=r(t) if count==`num'
	 capture tobit lnorigin_destination  l.Poast_barrier l.lnorigin_destination l.(civwar_intensity_o v2x_polyarchy_o genocide_o pts_a_o lngdppcconstant_o) lndist comlang_off colony  if year==`num', ll(0) ul(14) vce(cl dyad)
	 capture lincom l.Poast_barrier
	 capture replace Pp=r(p) if count==`num'
	 capture replace Pt=r(t) if count==`num'
}

label var Ht "Hassner & Wittenberg"
label var At "Avdan & Gelpi"
label var Pt "Poast & Carter"


twoway (scatter Ht count, symbol(t)) (scatter At count, symbol(o) yline(-2)) (scatter Pt count, symbol(s) yline(2)), saving(tobit_models,replace)

drop Hp Ht Ap At Pp Pt count

**********************************************************************
*** Appendix Tobit-IV figure
** Not reported in the Appendix, but this code from work product is shared
** for interested readers.
**********************************************************************
capture drop count
capture drop Hp Ap
gen count=_n+1989 in 1/27
gen Hp=.
gen Ap=.
gen Pp=.
gen Hz=.
gen Az=.
gen Pz=.
foreach num of numlist 1990(1)2016 {
	 capture ivtobit lnorigin_destination  (l.Hassner_barrier= mountain border_crossings ln_boundary_length) l.lnorigin_destination l.(civwar_intensity_o v2x_polyarchy_o genocide_o pts_a_o lngdppcconstant_o) lndist comlang_off colony  if year==`num', ll(0) ul(14) vce(cl dyad)
	 capture lincom l.Hassner_barrier
	 capture replace Hp=r(p) if count==`num'
	 capture replace Hz=r(z) if count==`num'
	 capture ivtobit lnorigin_destination  (l.Avdan_barrier= mountain border_crossings ln_boundary_length) l.lnorigin_destination l.(civwar_intensity_o v2x_polyarchy_o genocide_o pts_a_o lngdppcconstant_o) lndist comlang_off colony  if year==`num', ll(0) ul(14) vce(cl dyad)
	 capture lincom l.Avdan_barrier
	 capture replace Ap=r(p) if count==`num'
	 capture replace Az=r(z) if count==`num'
	 capture ivtobit lnorigin_destination  (l.Poast_barrier= mountain border_crossings ln_boundary_length) l.lnorigin_destination l.(civwar_intensity_o v2x_polyarchy_o genocide_o pts_a_o lngdppcconstant_o) lndist comlang_off colony  if year==`num', ll(0) ul(14) vce(cl dyad)
	 capture lincom l.Poast_barrier
	 capture replace Pp=r(p) if count==`num'
	 capture replace Pz=r(z) if count==`num'
}

label var Hz "Hassner & Wittenberg"
label var Az "Avdan & Gelpi"
label var Pz "Poast & Carter"


twoway (scatter Hz count, symbol(t)) (scatter Az count, symbol(o) yline(-2)) (scatter Pz count, symbol(s) yline(2)), saving(iv_models_log,replace)

drop Hp Hz Ap Az Pp Pz count



*************************************************************************
*** Diagnostics for IV-Poisson

capture drop count
gen count=_n+1989 in 1/27
gen Hd=.
gen Pd=.
gen Ad=.
foreach num of numlist 1990(1)2014 {
	 capture ivpoisson gmm lnorigin_destination  (l.Hassner_barrier= mountain border_crossings ln_boundary_length) l.(civwar_intensity_o v2x_polyarchy_o genocide_o pts_a_o lngdppcconstant_o) comlang_off colony  if year==`num', vce(cl dyad)
	 capture estat overid
	 capture replace Hd=r(J_p) if count==`num'
	 capture ivpoisson gmm lnorigin_destination  (l.Avdan_barrier= mountain border_crossings ln_boundary_length) l.(civwar_intensity_o v2x_polyarchy_o genocide_o lngdppcconstant_o) comlang_off colony  if year==`num' & year!=2014, vce(cl dyad)
	 capture estat overid
	 capture replace Ad=r(J_p) if count==`num'
	 capture ivpoisson gmm lnorigin_destination  (l.Poast_barrier= mountain border_crossings ln_boundary_length) l.(civwar_intensity_o v2x_polyarchy_o genocide_o pts_a_o lngdppcconstant_o) comlang_off colony  if year==`num', vce(cl dyad)
	 capture estat overid
	 capture replace Pd=r(J_p) if count==`num'
}

label var Hd "Hassner & Wittenberg"
label var Ad "Avdan & Gelpi"
label var Pd "Poast & Carter"


twoway (scatter Hd count, symbol(t)) (scatter Ad count, symbol(o) yline(-2)) (scatter Pd count, symbol(s) yline(2)), saving(ivpoisson_diagnostics,replace)

drop Hd Ad Pd count




